﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.Supervise.Model.Enum;

namespace HZ.Supervise.Web.Secondphase
{
    public partial class SortSourceRateOfCity : BasePage
    {
        string userid = "";

        string sortSource = "''";

        public SortSourceRateOfCity()
        {
            this.ModuleNo = Module.趋势走向.ToString();
            this.PageOperateType = OperateType.城市采购类型所占比例.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            userid = CurrentAccount.GetUser().UserID;

            if (!IsPostBack)
            {

                GvDataBind();

            }
        }
        /// <summary>
        /// 曹鹏
        /// 2011年5月20日11:01:06 
        /// 数据绑定
        /// </summary>
        private void GvDataBind()
        {
            //xg by张雄
            string timeFrom = string.Intern(this.txtTimeFrom.Text);
            string City = this.ddlCity.SelectedValue;
            string timeTo = string.Intern(this.txtTimeTo.Text);
            if (ddlSortSource.SelectedValue != "-1")
            {
                sortSource = this.ddlSortSource.SelectedValue;
            }
            string rate = this.txtRate.Text;

            string compare = this.ddlCompare.SelectedValue;

            string sort = ddlName.SelectedValue + "  " + ddlsort.SelectedValue;

            int total = 0;

            string areaGroupBy = "";

            DataTable dt = new DataTable();

            if (userid.Contains("root"))
            {

                areaGroupBy = " SUBSTRING(AreaID,0,5) ";

                dt = HZ.Supervise.BLLFactory.ExecuteContext().ExecuteRateOfAreaSource1(timeFrom, timeTo,City, areaGroupBy, sortSource, compare, this.txtRate.Text, sort, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out total);

                AspNetPager1.RecordCount = total;

                Function.ChangeRate(dt, "DistributeRate", "addDistributeRate");

                Function.ChangeRate(dt, "WareHouseRate", "addWareHouseRate");

                Function.AddColumn(dt, "sortsource");

                Function.ChangeRate(dt, "sortsourcerate", "addsortsourcerate");

            }
            else
            {

                dt = null;

            }

            this.gvwProcureCatalog.DataSource = dt;

            this.gvwProcureCatalog.DataBind();

        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {

            AspNetPager1.CurrentPageIndex = 1;

        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {

            GvDataBind();

        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            //xg by张雄
            string timeFrom = string.Intern(this.txtTimeFrom.Text);
            string City = this.ddlCity.SelectedValue;
            string timeTo = string.Intern(this.txtTimeTo.Text);

            if (ddlSortSource.SelectedValue != "-1")
            {
                sortSource = this.ddlSortSource.SelectedValue;
            }

            string rate = this.txtRate.Text;

            string compare = this.ddlCompare.SelectedValue;

            string sort = ddlName.SelectedValue + "  " + ddlsort.SelectedValue;

            int total = 0;

            string areaGroupBy = "";

            DataTable dt = new DataTable();

            if (userid.Contains("root"))
            {

                areaGroupBy = " SUBSTRING(AreaID,0,5) ";

                dt = HZ.Supervise.BLLFactory.ExecuteContext().ExecuteRateOfAreaSource1(timeFrom, timeTo,City, areaGroupBy, sortSource, compare, this.txtRate.Text, sort, 0, 1, out total);

                AspNetPager1.RecordCount = total;

                Function.ChangeRate(dt, "DistributeRate", "addDistributeRate");

                Function.ChangeRate(dt, "WareHouseRate", "addWareHouseRate");

                Function.AddColumn(dt, "sortsource");

                Function.ChangeRate(dt, "sortsourcerate", "addsortsourcerate");

                HZ.Excel.ExcelHelper.ExportDataForWeb(dt, this.gvwProcureCatalog);

            }

        }
    }
}
